﻿namespace HRM.CORE.Process
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Grid;
    using APP.HELPER;
    using HRM.CORE;
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using APP.HELPER.Utils.Language;
    using Extra.ERP;

    public class xucTrainingAdd : Common.xucBaseAddH
    {
        private TextEdit cboDecideNumber;
        private TextEdit cboPerson;
        private GridColumn colEmployeeCode;
        private GridColumn colFirstName;
        private GridColumn colLastName;
        private IContainer components = null;
        private DateEdit dtBeginDate;
        private DateEdit dtDate;
        private GridLookUpEdit glkEmployeeCode;
        private GridView gridLookUpEdit1View;
        private GroupControl grInformation;
        private LabelControl labelControl1;
        private LabelControl labelControl7;
        private LabelControl lcBeginDate;
        private LabelControl lcDate;
        private LabelControl lcDecideNumber;
        private LabelControl lcForm;
        private LabelControl lcPerson;
        private LabelControl lcReason;
        private LabelControl lcTime;
        private LabelControl lcTrainingName;
        private string m_EmployeeCode = "";
        private Guid m_TrainingID = Guid.Empty;
        private TextEdit txtEmployeeName;
        private ButtonEdit txtFilePath;
        private TextEdit txtForm;
        private TextEdit txtReason;
        private TextEdit txtTime;
        private TextEdit txtTrainingName;

        public event SuccessEventHander Success;

        public xucTrainingAdd()
        {
            this.InitializeComponent();
            this.InitData();
            this.InitComponent();
        }

        protected override void Add()
        {
            base.Add();
            HRM_PROCESS_TRAINING hrm_process_training = new HRM_PROCESS_TRAINING();
            this.txtTrainingName.Focus();
            this.glkEmployeeCode.Enabled = true;
        }

        public void Clear()
        {
            this.txtTrainingName.Text = "";
            this.txtReason.Text = "";
            this.txtForm.Text = "";
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void glkEmployeeCode_EditValueChanged(object sender, EventArgs e)
        {
            this.m_EmployeeCode = this.glkEmployeeCode.EditValue.ToString();
            this.LoadEmployeeInformation();
        }

        protected override void Init()
        {
        }

        private void InitComponent()
        {
            this.dtBeginDate.DateTime = DateTime.Now;
            this.dtDate.DateTime = DateTime.Now;
        }

        private void InitData()
        {
            new HRM_EMPLOYEE().AddGridLookupEdit(this.glkEmployeeCode);
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucTrainingAdd));
            SerializableAppearanceObject appearance = new SerializableAppearanceObject();
            this.grInformation = new GroupControl();
            this.labelControl1 = new LabelControl();
            this.txtEmployeeName = new TextEdit();
            this.glkEmployeeCode = new GridLookUpEdit();
            this.gridLookUpEdit1View = new GridView();
            this.colEmployeeCode = new GridColumn();
            this.colFirstName = new GridColumn();
            this.colLastName = new GridColumn();
            this.dtBeginDate = new DateEdit();
            this.lcBeginDate = new LabelControl();
            this.lcTime = new LabelControl();
            this.txtTime = new TextEdit();
            this.lcForm = new LabelControl();
            this.txtForm = new TextEdit();
            this.lcTrainingName = new LabelControl();
            this.lcReason = new LabelControl();
            this.dtDate = new DateEdit();
            this.txtReason = new TextEdit();
            this.txtTrainingName = new TextEdit();
            this.lcDecideNumber = new LabelControl();
            this.lcDate = new LabelControl();
            this.lcPerson = new LabelControl();
            this.cboPerson = new TextEdit();
            this.cboDecideNumber = new TextEdit();
            this.txtFilePath = new ButtonEdit();
            this.labelControl7 = new LabelControl();
            ((ISupportInitialize) base.Err).BeginInit();
            base.imageCollection2.BeginInit();
            this.grInformation.BeginInit();
            this.grInformation.SuspendLayout();
            this.txtEmployeeName.Properties.BeginInit();
            this.glkEmployeeCode.Properties.BeginInit();
            this.gridLookUpEdit1View.BeginInit();
            this.dtBeginDate.Properties.VistaTimeProperties.BeginInit();
            this.dtBeginDate.Properties.BeginInit();
            this.txtTime.Properties.BeginInit();
            this.txtForm.Properties.BeginInit();
            this.dtDate.Properties.VistaTimeProperties.BeginInit();
            this.dtDate.Properties.BeginInit();
            this.txtReason.Properties.BeginInit();
            this.txtTrainingName.Properties.BeginInit();
            this.cboPerson.Properties.BeginInit();
            this.cboDecideNumber.Properties.BeginInit();
            this.txtFilePath.Properties.BeginInit();
            base.SuspendLayout();
            base.btnSave.Location = new Point(0x83, 0x101);
            base.btnSave.TabIndex = 1;
            base.btnCancel.Location = new Point(330, 0x101);
            base.btnCancel.TabIndex = 3;
            base.btnSaveNew.Location = new Point(0xe5, 0x101);
            base.btnSaveNew.TabIndex = 2;
            base.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.grInformation.Controls.Add(this.labelControl1);
            this.grInformation.Controls.Add(this.txtEmployeeName);
            this.grInformation.Controls.Add(this.glkEmployeeCode);
            this.grInformation.Controls.Add(this.dtBeginDate);
            this.grInformation.Controls.Add(this.lcBeginDate);
            this.grInformation.Controls.Add(this.lcTime);
            this.grInformation.Controls.Add(this.txtTime);
            this.grInformation.Controls.Add(this.lcForm);
            this.grInformation.Controls.Add(this.txtForm);
            this.grInformation.Controls.Add(this.lcTrainingName);
            this.grInformation.Controls.Add(this.lcReason);
            this.grInformation.Controls.Add(this.dtDate);
            this.grInformation.Controls.Add(this.txtReason);
            this.grInformation.Controls.Add(this.txtTrainingName);
            this.grInformation.Controls.Add(this.lcDecideNumber);
            this.grInformation.Controls.Add(this.lcDate);
            this.grInformation.Controls.Add(this.lcPerson);
            this.grInformation.Controls.Add(this.cboPerson);
            this.grInformation.Controls.Add(this.cboDecideNumber);
            this.grInformation.Dock = DockStyle.Top;
            this.grInformation.Location = new Point(0, 0);
            this.grInformation.Name = "grInformation";
            this.grInformation.Size = new Size(0x1ba, 0xf8);
            this.grInformation.TabIndex = 0;
            this.grInformation.Text = "Th\x00f4ng Tin Đ\x00e0o Tạo";
            this.labelControl1.AllowHtmlString = true;
            this.labelControl1.Location = new Point(9, 0x23);
            this.labelControl1.Name = "labelControl1";
            this.labelControl1.Size = new Size(0x60, 14);
            this.labelControl1.TabIndex = 0;
            this.labelControl1.Text = "Chọn nh\x00e2n vi\x00ean <color=red>(*)</color>:";
            this.txtEmployeeName.Enabled = false;
            this.txtEmployeeName.Location = new Point(0xf1, 0x20);
            this.txtEmployeeName.Name = "txtEmployeeName";
            this.txtEmployeeName.Size = new Size(0xb8, 20);
            this.txtEmployeeName.TabIndex = 2;
            this.glkEmployeeCode.Location = new Point(0x7c, 0x20);
            this.glkEmployeeCode.Name = "glkEmployeeCode";
            this.glkEmployeeCode.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.glkEmployeeCode.Properties.NullText = "[Chọn nh\x00e2n vi\x00ean]";
            this.glkEmployeeCode.Properties.View = this.gridLookUpEdit1View;
            this.glkEmployeeCode.Size = new Size(110, 20);
            this.glkEmployeeCode.TabIndex = 1;
            this.glkEmployeeCode.EditValueChanged += new EventHandler(this.glkEmployeeCode_EditValueChanged);
            this.gridLookUpEdit1View.Columns.AddRange(new GridColumn[] { this.colEmployeeCode, this.colFirstName, this.colLastName });
            this.gridLookUpEdit1View.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            this.gridLookUpEdit1View.Name = "gridLookUpEdit1View";
            this.gridLookUpEdit1View.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridLookUpEdit1View.OptionsView.ShowAutoFilterRow = true;
            this.gridLookUpEdit1View.OptionsView.ShowGroupPanel = false;
            this.colEmployeeCode.Caption = "M\x00e3 nh\x00e2n vi\x00ean";
            this.colEmployeeCode.FieldName = "EmployeeCode";
            this.colEmployeeCode.Name = "colEmployeeCode";
            this.colEmployeeCode.Visible = true;
            this.colEmployeeCode.VisibleIndex = 0;
            this.colFirstName.Caption = "Họ l\x00f3t";
            this.colFirstName.FieldName = "FirstName";
            this.colFirstName.Name = "colFirstName";
            this.colFirstName.Visible = true;
            this.colFirstName.VisibleIndex = 1;
            this.colLastName.Caption = "T\x00ean";
            this.colLastName.FieldName = "LastName";
            this.colLastName.Name = "colLastName";
            this.colLastName.Visible = true;
            this.colLastName.VisibleIndex = 2;
            this.dtBeginDate.EditValue = null;
            this.dtBeginDate.Location = new Point(0x145, 0x9c);
            this.dtBeginDate.Name = "dtBeginDate";
            this.dtBeginDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtBeginDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtBeginDate.Size = new Size(100, 20);
            this.dtBeginDate.TabIndex = 12;
            this.lcBeginDate.Location = new Point(0xf1, 0x9e);
            this.lcBeginDate.Name = "lcBeginDate";
            this.lcBeginDate.Size = new Size(0x45, 13);
            this.lcBeginDate.TabIndex = 11;
            this.lcBeginDate.Text = "Ng\x00e0y bắt đầu:";
            this.lcTime.Location = new Point(9, 0x9f);
            this.lcTime.Name = "lcTime";
            this.lcTime.Size = new Size(0x57, 13);
            this.lcTime.TabIndex = 9;
            this.lcTime.Text = "Thời gian đ\x00e0o tạo:";
            this.txtTime.Location = new Point(0x7a, 0x9c);
            this.txtTime.Name = "txtTime";
            this.txtTime.Size = new Size(0x70, 20);
            this.txtTime.TabIndex = 10;
            this.lcForm.Location = new Point(9, 130);
            this.lcForm.Name = "lcForm";
            this.lcForm.Size = new Size(90, 13);
            this.lcForm.TabIndex = 7;
            this.lcForm.Text = "H\x00ecnh thức đ\x00e0o tạo:";
            this.txtForm.Location = new Point(0x7a, 0x7f);
            this.txtForm.Name = "txtForm";
            this.txtForm.Size = new Size(0x12f, 20);
            this.txtForm.TabIndex = 8;
            this.lcTrainingName.Location = new Point(9, 0x45);
            this.lcTrainingName.Name = "lcTrainingName";
            this.lcTrainingName.Size = new Size(0x6b, 13);
            this.lcTrainingName.TabIndex = 3;
            this.lcTrainingName.Text = "Chương tr\x00ecnh đ\x00e0o tạo:";
            this.lcReason.Location = new Point(9, 100);
            this.lcReason.Name = "lcReason";
            this.lcReason.Size = new Size(70, 13);
            this.lcReason.TabIndex = 5;
            this.lcReason.Text = "L\x00fd do đ\x00e0o tạo:";
            this.dtDate.EditValue = null;
            this.dtDate.Location = new Point(0x145, 0xbb);
            this.dtDate.Name = "dtDate";
            this.dtDate.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.dtDate.Properties.VistaTimeProperties.Buttons.AddRange(new EditorButton[] { new EditorButton() });
            this.dtDate.Size = new Size(100, 20);
            this.dtDate.TabIndex = 0x10;
            this.txtReason.Location = new Point(0x7a, 0x61);
            this.txtReason.Name = "txtReason";
            this.txtReason.Size = new Size(0x12f, 20);
            this.txtReason.TabIndex = 6;
            this.txtTrainingName.Location = new Point(0x7a, 0x43);
            this.txtTrainingName.Name = "txtTrainingName";
            this.txtTrainingName.Size = new Size(0x12f, 20);
            this.txtTrainingName.TabIndex = 4;
            this.lcDecideNumber.Location = new Point(9, 0xbd);
            this.lcDecideNumber.Name = "lcDecideNumber";
            this.lcDecideNumber.Size = new Size(70, 13);
            this.lcDecideNumber.TabIndex = 13;
            this.lcDecideNumber.Text = "Số quyết định:";
            this.lcDate.Location = new Point(0xf1, 0xbd);
            this.lcDate.Name = "lcDate";
            this.lcDate.Size = new Size(0x4d, 13);
            this.lcDate.TabIndex = 15;
            this.lcDate.Text = "Ng\x00e0y ban h\x00e0nh:";
            this.lcPerson.Location = new Point(9, 0xda);
            this.lcPerson.Name = "lcPerson";
            this.lcPerson.Size = new Size(80, 13);
            this.lcPerson.TabIndex = 0x11;
            this.lcPerson.Text = "Người ban h\x00e0nh:";
            this.cboPerson.Location = new Point(0x7a, 0xd8);
            this.cboPerson.Name = "cboPerson";
            this.cboPerson.Size = new Size(0x12f, 20);
            this.cboPerson.TabIndex = 0x12;
            this.cboDecideNumber.Location = new Point(0x7a, 0xba);
            this.cboDecideNumber.Name = "cboDecideNumber";
            this.cboDecideNumber.Size = new Size(0x70, 20);
            this.cboDecideNumber.TabIndex = 14;
            this.txtFilePath.Location = new Point(0x33, 0x106);
            this.txtFilePath.Name = "txtFilePath";
            this.txtFilePath.Properties.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Glyph, "", -1, true, true, false, ImageLocation.MiddleCenter, (Image) manager.GetObject("txtFilePath.Properties.Buttons"), new KeyShortcut(Keys.None), appearance, "", "Browse", null, true) });
            this.txtFilePath.Properties.ButtonClick += new ButtonPressedEventHandler(this.txtFilePath_Properties_ButtonClick);
            this.txtFilePath.Size = new Size(0x47, 0x16);
            this.txtFilePath.TabIndex = 0x11;
            this.txtFilePath.TabStop = false;
            this.txtFilePath.Visible = false;
            this.labelControl7.Location = new Point(9, 0x10a);
            this.labelControl7.Name = "labelControl7";
            this.labelControl7.Size = new Size(0x27, 13);
            this.labelControl7.TabIndex = 0x10;
            this.labelControl7.Text = "Tập Tin:";
            this.labelControl7.Visible = false;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.grInformation);
            base.Controls.Add(this.labelControl7);
            base.Controls.Add(this.txtFilePath);
            base.Name = "xucTrainingAdd";
            base.Size = new Size(0x1ba, 0x125);
            base.Controls.SetChildIndex(this.txtFilePath, 0);
            base.Controls.SetChildIndex(this.labelControl7, 0);
            base.Controls.SetChildIndex(base.btnCancel, 0);
            base.Controls.SetChildIndex(base.btnSave, 0);
            base.Controls.SetChildIndex(base.btnSaveNew, 0);
            base.Controls.SetChildIndex(this.grInformation, 0);
            ((ISupportInitialize) base.Err).EndInit();
            base.imageCollection2.EndInit();
            this.grInformation.EndInit();
            this.grInformation.ResumeLayout(false);
            this.grInformation.PerformLayout();
            this.txtEmployeeName.Properties.EndInit();
            this.glkEmployeeCode.Properties.EndInit();
            this.gridLookUpEdit1View.EndInit();
            this.dtBeginDate.Properties.VistaTimeProperties.EndInit();
            this.dtBeginDate.Properties.EndInit();
            this.txtTime.Properties.EndInit();
            this.txtForm.Properties.EndInit();
            this.dtDate.Properties.VistaTimeProperties.EndInit();
            this.dtDate.Properties.EndInit();
            this.txtReason.Properties.EndInit();
            this.txtTrainingName.Properties.EndInit();
            this.cboPerson.Properties.EndInit();
            this.cboDecideNumber.Properties.EndInit();
            this.txtFilePath.Properties.EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void InitMultiLanguages()
        {
            this.grInformation.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "grInformation", this.grInformation.Text);
            this.lcTrainingName.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "TrainingName", this.lcTrainingName.Text);
            this.lcReason.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "Reason", this.lcReason.Text);
            this.lcForm.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "Form", this.lcForm.Text);
            this.lcTime.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "Time", this.lcTime.Text);
            this.lcBeginDate.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "BeginDate", this.lcBeginDate.Text);
            this.lcDate.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "Date", this.lcDate.Text);
            this.lcPerson.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "Person", this.lcPerson.Text);
            this.lcDecideNumber.Text = MultiLanguages.GetString("tbl_ProcessTrainingAdd", "DecideNumber", this.lcDecideNumber.Text);
        }

        private void LoadEmployeeInformation()
        {
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            hrm_employee.Get(this.m_EmployeeCode);
            this.grInformation.Text = "Th\x00f4ng Tin Đ\x00e0o Tạo - " + hrm_employee.EmployeeCode + " (" + hrm_employee.FirstName + " " + hrm_employee.LastName + ")";
            this.txtEmployeeName.Text = hrm_employee.FirstName + " " + hrm_employee.LastName;
        }

        private void RaiseSuccessEventHander(HRM_PROCESS_TRAINING item)
        {
            if (this.Success != null)
            {
                this.Success(this, item);
            }
        }

        public void SetCode(string EmployeeCode)
        {
            this.m_EmployeeCode = EmployeeCode;
            if (this.m_EmployeeCode != "")
            {
                this.glkEmployeeCode.EditValue = this.m_EmployeeCode;
                this.LoadEmployeeInformation();
            }
        }

        public void SetData(HRM_PROCESS_TRAINING item)
        {
            this.m_TrainingID = item.TrainingID;
            SYS_LOG.Insert("Qu\x00e1 Tr\x00ecnh Đ\x00e0o Tạo", "Xem", this.m_TrainingID.ToString());
            this.m_EmployeeCode = item.EmployeeCode;
            this.glkEmployeeCode.EditValue = this.m_EmployeeCode;
            this.glkEmployeeCode.Enabled = false;
            this.txtTrainingName.Text = item.TrainingName;
            this.txtReason.Text = item.Reason;
            this.txtForm.Text = item.Form;
            this.txtTime.Text = item.Time;
            this.dtBeginDate.DateTime = item.BeginDate;
            this.cboDecideNumber.Text = item.DecideNumber;
            this.dtDate.DateTime = item.Date;
            this.cboPerson.Text = item.Person;
            this.txtFilePath.Text = item.FilePath;
            this.LoadEmployeeInformation();
        }

        private void txtFilePath_Properties_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog {
                Filter = "All File(*.*)|*.*",
                FilterIndex = 0
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.txtFilePath.Text = dialog.FileName;
            }
        }

        protected override string uc_Change()
        {
            return string.Empty;
        }

        protected override string uc_Delete()
        {
            HRM_PROCESS_TRAINING item = new HRM_PROCESS_TRAINING {
                TrainingID = this.m_TrainingID
            };
            string str = item.Delete();
            if (str == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            return str;
        }

        protected override string uc_Save()
        {
            if (this.m_EmployeeCode == "")
            {
                XtraMessageBox.Show("Vui l\x00f2ng chọn nh\x00e2n vi\x00ean để lưu dữ liệu!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK);
                return "";
            }
            SYS_LOG.Insert("Qu\x00e1 Tr\x00ecnh Đ\x00e0o Tạo", "Th\x00eam", this.m_TrainingID.ToString());
            base.SetWaitDialogCaption("Đang lưu dữ liệu...");
            Cursor.Current = Cursors.WaitCursor;
            HRM_PROCESS_TRAINING item = new HRM_PROCESS_TRAINING {
                TrainingID = Guid.NewGuid(),
                EmployeeCode = this.m_EmployeeCode,
                TrainingName = this.txtTrainingName.Text,
                Reason = this.txtReason.Text,
                Form = this.txtForm.Text,
                Time = this.txtTime.Text,
                BeginDate = this.dtBeginDate.DateTime,
                Date = this.dtDate.DateTime,
                DecideNumber = this.cboDecideNumber.Text,
                Person = this.cboPerson.Text,
                FilePath = this.txtFilePath.Text
            };
            string text = item.Insert();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            Cursor.Current = Cursors.Default;
            this.DoHide();
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return text;
        }

        protected override string uc_Update()
        {
            SYS_LOG.Insert("Qu\x00e1 Tr\x00ecnh Đ\x00e0o Tạo", "Cập Nhật", this.m_TrainingID.ToString());
            base.SetWaitDialogCaption("Đang cập nhật dữ liệu...");
            HRM_PROCESS_TRAINING item = new HRM_PROCESS_TRAINING {
                TrainingID = this.m_TrainingID,
                EmployeeCode = this.m_EmployeeCode,
                TrainingName = this.txtTrainingName.Text,
                Reason = this.txtReason.Text,
                Form = this.txtForm.Text,
                Time = this.txtTime.Text,
                BeginDate = this.dtBeginDate.DateTime,
                Date = this.dtDate.DateTime,
                DecideNumber = this.cboDecideNumber.Text,
                Person = this.cboPerson.Text,
                FilePath = this.txtFilePath.Text
            };
            string text = item.Update();
            if (text == "OK")
            {
                this.RaiseSuccessEventHander(item);
            }
            if (text != "OK")
            {
                XtraMessageBox.Show(text, "Cảnh B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            this.DoHide();
            return text;
        }

        public delegate void SuccessEventHander(object sender, HRM_PROCESS_TRAINING item);
    }
}

